﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default3.aspx.cs" Inherits="Default3" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <div>
        <table id="tb_ventas" runat="server" style="width: 80%; azimuth: center">
            <tr id="Tr1" runat="server">
                <td id="Td1" colspan="6" align="center" runat="server">
                    <h2>
                        Ventas
                    </h2>
                </td>
            </tr>
            <tr id="Tr2" runat="server">
                <td id="Td2" align="right" style="width: 92px" runat="server">
                    <asp:Label ID="lb_numero" runat="server" Text="Nº: "></asp:Label>
                </td>
                <td id="Td3" style="width: 10px" runat="server">
                </td>
                <td id="Td4" style="width: 167px" runat="server">
                    <asp:TextBox ID="txt_numero_factura" runat="server" Height="19px" Width="47px" onkeypress="return ningunCaracter(event)"></asp:TextBox>
                    <asp:Label ID="lb_Estado" runat="server" ForeColor="Red" Text="Finalizado" Visible="False"></asp:Label>
                    <asp:Label ID="lb_FacturaGuardada" runat="server" Text="no" Visible="False"></asp:Label>
                    <asp:Label ID="lb_numero_pago" runat="server" Visible="False"></asp:Label>
                </td>
                <td id="Td5" align="right" style="width: 101px" runat="server">
                    <asp:Label ID="lb_fechaTexto" runat="server" Text="Fecha: "></asp:Label>
                </td>
                <td id="Td6" style="width: 10px" runat="server">
                </td>
                <td id="Td7" style="width: 150px" runat="server">
                    <asp:Label ID="lb_Fecha" runat="server"></asp:Label>
                </td>
            </tr>
            <tr id="Tr3" runat="server">
                <td id="Td8" style="width: 92px" align="right" runat="server">
                    <asp:Label ID="lb_nombre_cliente" runat="server" Text="Cliente:"></asp:Label>
                </td>
                <td id="Td9" style="width: 10px" runat="server">
                </td>
                <td id="Td10" style="width: 167px" runat="server">
                    <asp:TextBox ID="txt_nombre_cliente" onkeypress="return ningunCaracter(event);" runat="server"
                        Width="125px"></asp:TextBox>
                    <asp:ImageButton ID="imgbt_Clientes" runat="server" Width="25px" Height="20px" ImageUrl="~/images/lupa.png"
                        OnClientClick="popUpClientes(); return false" ToolTip="Buscar Cliente"></asp:ImageButton>
                    <asp:Label ID="lb_Error_Cliente" runat="server" ForeColor="Red" Text="*" Visible="False"></asp:Label>
                </td>
                <td id="Td11" style="width: 101px" align="right" runat="server">
                    <asp:Label ID="lb_CodCliente" runat="server" Text="Codigo Cliente: "></asp:Label>
                </td>
                <td id="Td12" style="width: 10px" runat="server">
                </td>
                <td id="Td13" style="width: 150px" runat="server">
                    <asp:TextBox ID="txt_cod_cliente" onkeypress="return ningunCaracter(event);" runat="server"
                        Width="30px"></asp:TextBox>
                </td>
            </tr>
            <tr id="Tr4" runat="server">
                <td id="Td14" style="width: 92px; height: 40px;" align="right" runat="server">
                    <asp:Label ID="lb_Producto" runat="server" Text="Producto: "></asp:Label>
                </td>
                <td id="Td15" style="width: 10px; height: 40px;" runat="server">
                </td>
                <td id="Td16" style="width: 167px; height: 40px;" runat="server">
                    <asp:TextBox ID="txt_nombre_Producto" runat="server" onkeypress="return ningunCaracter(event);"
                        Height="20px" Width="127px"></asp:TextBox>
                    <asp:ImageButton Style="height: 20px" ID="imgbt_Producto" runat="server" ImageUrl="~/images/lupa.png"
                        OnClientClick="popUpProductos(); return false" ToolTip="Buscar Producto" Height="16px"
                        Width="25px"></asp:ImageButton>
                    <asp:Label ID="lb_Error_Producto" runat="server" ForeColor="Red" Text="*" Visible="False"></asp:Label>
                </td>
                <td id="Td17" style="width: 101px; height: 40px;" align="right" runat="server">
                    <asp:Label ID="lb_cantidad" runat="server" Text="Cantidad: "></asp:Label>
                </td>
                <td id="Td18" style="width: 10px; height: 40px;" runat="server">
                </td>
                <td id="Td19" style="width: 150px; height: 40px;" runat="server">
                    <asp:TextBox ID="txt_cantidadTex" onkeypress="return solonumeros(event)" runat="server"
                        Width="54px" Height="20px" MaxLength="6"></asp:TextBox>
                    <asp:Label ID="lb_Error_Cantidad" runat="server" ForeColor="Red" Text="*" Visible="False"></asp:Label>
                    <asp:ImageButton ID="imgbt_agregar_producto" runat="server" Height="16px" ImageUrl="~/images/agregar.png"
                        Width="23px" OnClick="imgbt_agregar_producto_Click" ToolTip="agregar producto" />
                </td>
            </tr>
            <tr id="Tr5" runat="server">
                <td id="Td20" style="width: 92px" align="right" runat="server">
                    <asp:Label ID="lb_cod_producto" runat="server" Text="Codigo del Producto: "></asp:Label>
                </td>
                <td id="Td21" style="width: 10px" runat="server">
                </td>
                <td id="Td22" style="width: 167px" runat="server">
                    <asp:TextBox ID="txt_cod_producto" onkeypress="return ningunCaracter(event);" runat="server"
                        Height="20px" Width="30px"></asp:TextBox>
                </td>
                <td id="Td23" style="width: 101px" align="right" runat="server">
                    <asp:Label ID="lb_precio_prod" runat="server" Text="Precio c/u: "></asp:Label>
                </td>
                <td id="Td24" style="width: 10px" runat="server">
                </td>
                <td id="Td25" style="width: 150px" runat="server">
                    <asp:TextBox ID="txt_precio_producto" onkeypress="return ningunCaracter(event);"
                        runat="server" Width="81px" Height="20px"></asp:TextBox>
                </td>
            </tr>
            <tr id="tr_guardar_producto" runat="server">
                <td id="Td26" runat="server" colspan="3" align="center">
                </td>
                <td runat="server" colspan="3">
                    <asp:GridView ID="GView_Detalle_Factura" runat="server" AllowPaging="True" CellPadding="4"
                        ForeColor="#333333" Width="70%" OnRowCommand="GridViewf_OnRowCommand">
                        <AlternatingRowStyle BackColor="#CCCCCC" />
                        <Columns>
                            <asp:TemplateField HeaderText="Editar">
                                <ItemTemplate>
                                    <asp:ImageButton ID="imgbt_editar" runat="server" CommandName="editar" ImageUrl="~/images/seleccionar.png"
                                        CommandArgument="<%# ((GridViewRow) Container).RowIndex %>" />
                                </ItemTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="Borrar">
                                <ItemTemplate>
                                    <asp:ImageButton ID="imgbt_borrar" runat="server" CommandName="borrar" ImageUrl="~/images/borrar.png"
                                        CommandArgument="<%# ((GridViewRow) Container).RowIndex %>" />
                                </ItemTemplate>
                            </asp:TemplateField>
                        </Columns>
                        <FooterStyle BackColor="#CCCCCC" />
                        <HeaderStyle BackColor="Black" Font-Bold="True" ForeColor="White" />
                        <PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
                        <SelectedRowStyle BackColor="#000099" Font-Bold="True" ForeColor="White" />
                    </asp:GridView>
                    <asp:Button ID="bt_guardar_editado" runat="server" Text="actualizar" Visible="false" OnClick="bt_guardar_editado_Click" />
                </td>
            </tr>
            <tr id="tr_grid_detalle_ventas" runat="server" style="width: 100%">
                <td id="Td28" colspan="6" runat="server" align="center">
                    <asp:Label ID="lb_Error_Texto" runat="server" ForeColor="Red" Text="Los Campos * debe ser completado"
                        Visible="False"></asp:Label>
                    <asp:Label ID="L_FacturaGuardada" runat="server" Text="no" Visible="False"></asp:Label>
                </td>
            </tr>
            <tr id="Tr6" runat="server">
                <td id="Td29" align="center" style="width: 92px" colspan="6" runat="server">
                </td>
            </tr>
            <tr id="tr_guardar_cabecera" runat="server">
                <td id="Td30" colspan="5" runat="server">
                </td>
                <td id="Td_guardar_factura" align="center" runat="server">
                    <asp:ImageButton ID="imgbt_guardar_factura" runat="server" Height="27px" ImageUrl="~/images/filesave.png"
                        ToolTip="Guardar Factura" Width="27px" OnClick="imgbt_guardar_factura_Click">
                    </asp:ImageButton>
                    <asp:ImageButton ID="imgbt_cancelar_factura" runat="server" Height="27px" ImageUrl="~/images/cancelar.jpg"
                        Width="27px" OnClick="imgbt_cancelar_factura_Click"></asp:ImageButton>
                </td>
            </tr>
            <tr id="Tr7" runat="server">
                <td id="Td32" colspan="5" runat="server">
                    <asp:Label ID="lb_total_a_pagar" runat="server" Text="Total a pagar: "></asp:Label>
                </td>
                <td id="Td33" align="center" runat="server">
                    <asp:TextBox ID="txt_total_a_pagar" runat="server" onkeypress="return ningunCaracter(event);"></asp:TextBox>
                </td>
            </tr>
        </table>
        <table id="tb_pagos" runat="server" style="width: 80%" visible="False">
            <tr id="Tr20" runat="server">
                <td id="Td34" colspan="4" runat="server">
                    <br />
                    <h2>
                        Forma de Pagos
                    </h2>
                </td>
            </tr>
            <tr id="Tr8" runat="server">
                <td id="Td35" align="right" style="width: 202px" runat="server">
                    <asp:Label ID="lb_valor_restante" runat="server" Text="Valor restante a pagar"></asp:Label>
                </td>
                <td id="Td36" style="width: 10px" runat="server">
                </td>
                <td id="Td37" style="width: 167px" runat="server">
                    <asp:TextBox ID="txt_valor_restante" runat="server" onkeypress="return ningunCaracter(event);" ></asp:TextBox>
                </td>
                <td id="Td38" runat="server" style="width: 222px">
                </td>
            </tr>
            <tr id="Tr9" runat="server">
                <td id="Td39" align="right" style="width: 202px" runat="server">
                    <asp:Label ID="lb_forma_de_pago" runat="server" Text="Forma de Pago:"></asp:Label>
                </td>
                <td id="Td40" style="width: 10px" runat="server">
                </td>
                <td id="Td41" style="width: 167px" runat="server">
                    <asp:DropDownList ID="dl_forma_de_pago" runat="server" DataSourceID="SqlDataSource4"
                        DataTextField="nombre" DataValueField="cod_forma_de_pago">
                    </asp:DropDownList>
                    <asp:SqlDataSource ID="SqlDataSource4" runat="server" ConnectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\ventas.mdf;Integrated Security=True;User Instance=True"
                        ProviderName="System.Data.SqlClient" SelectCommand="SELECT [cod_forma_de_pago], [nombre] FROM [forma_de_pago]">
                    </asp:SqlDataSource>
                </td>
                <td id="Td42" runat="server" style="width: 222px">
                </td>
            </tr>
            <tr id="Tr21" runat="server">
                <td id="Td223" align="right" style="width: 202px" runat="server">
                    <asp:Label ID="lb_cuenta_bancaria" runat="server" Text="Cuenta bancaria"></asp:Label>
                </td>
                <td id="Td233" style="width: 10px" runat="server">
                </td>
                <td id="Td243" style="width: 167px" runat="server">
                    <asp:TextBox ID="txt_cuenta_bancaria" runat="server"></asp:TextBox>
                </td>
                <td id="Td253" runat="server" style="width: 222px">
                </td>
            </tr>
            <tr id="Td263" runat="server">
                <td id="Td122" align="right" style="width: 202px" runat="server">
                    <asp:Label ID="lb_numero_cuenta" runat="server" Text="Numero:"></asp:Label>
                </td>
                <td id="Td132" style="width: 10px" runat="server">
                </td>
                <td id="Td145" style="width: 167px" runat="server">
                    <asp:TextBox ID="txt_numero_cuenta" runat="server" onkeypress="return solonumeros(event)"></asp:TextBox>
                </td>
                <td id="Td154" runat="server" style="width: 222px">
                </td>
            </tr>
            <tr id="Tr551" runat="server">
                <td id="Td169" align="right" style="width: 202px" runat="server">
                    <asp:Label ID="lb_monto" runat="server" Text="Monto"></asp:Label>
                </td>
                <td id="Td178" style="width: 10px" runat="server">
                </td>
                <td id="Td183" style="width: 167px" runat="server">
                    <asp:TextBox ID="txt_monto" runat="server" onkeypress="return solonumeros(event);"></asp:TextBox>
                </td>
                <td id="Td198" runat="server" style="width: 222px">
                </td>
            </tr>
            <tr id="Tr65" runat="server">
                <td id="Td201" align="right" runat="server" colspan="3">
                </td>
                <td id="Td218" style="width: 10px" runat="server">
                    <asp:ImageButton ID="imgbt_agregar_Pago" runat="server" Height="27px" ImageUrl="~/images/OK.png"
                        ToolTip="Agregar Pago" Width="27px" OnClick="imgbt_agregar_Pago_Click"></asp:ImageButton>
                    <asp:ImageButton ID="imgbt_finalizar_Pago" runat="server" Height="27px" ImageUrl="~/images/filesave.png"
                        ToolTip="Guardar factura" Width="27px" OnClick="imgbt_finalizar_Pago_Click">
                    </asp:ImageButton>
                </td>
            </tr>
            <tr runat="server">
                <td colspan="4" runat="server" align="center">
                    <br />
                    <br />
                    <asp:GridView ID="GridView_pagos" runat="server" AllowPaging="True" ForeColor="Black" HorizontalAlign="Center" BackColor="White"
                        BorderColor="#999999" CellPadding="5" BorderWidth="1px" PageSize="5" OnRowCommand="GridPagos_OnRowCommand">
                        <Columns>
                             <asp:TemplateField HeaderText="Editar">
                                <ItemTemplate>
                                    <asp:ImageButton ID="imgbt_editar_pagos" runat="server" CommandName="editar_pagos" ImageUrl="~/images/seleccionar.png"
                                        CommandArgument="<%# ((GridViewRow) Container).RowIndex %>" />
                                </ItemTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="Borrar">
                                <ItemTemplate>
                                    <asp:ImageButton ID="imgbt_borrar_pagos" runat="server" CommandName="borrar_pagos" ImageUrl="~/images/borrar.png"
                                        CommandArgument="<%# ((GridViewRow) Container).RowIndex %>" />
                                </ItemTemplate>
                            </asp:TemplateField>
                           </Columns>
                        <FooterStyle BackColor="#CCCCCC" />
                        <PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
                        <SelectedRowStyle BackColor="#000099" Font-Bold="True" ForeColor="White" />
                        <HeaderStyle BackColor="Black" Font-Bold="True" ForeColor="White" />
                        <AlternatingRowStyle BackColor="#CCCCCC" />
                    </asp:GridView>
                    <br />
                    <asp:Button ID="bt_editar_pagos" runat="server" Text="actualizar" 
                        onclick="bt_editar_pagos_Click" visible="false"/>
                    <br />
                </td>
            </tr>
        </table>
    </div>
    </form>
</body>

<script language="JavaScript">
    function popUpProductos() {
        window.open('Gridviews/productosGrid.aspx', '', 'center=yes,resizable=yes,scrollbars=yes');
    }
    function popUpClientes() {
        window.open('gridviews/clientesGrid.aspx', '', 'center=yes,resizable=yes,scrollbars=yes');
    }

    function retornaCodigoProducto(values) {
        var textProducto = $get('<%=this.txt_cod_producto.ClientID%>');
        textProducto.value = values;
    }

    function retornaNombreProducto(values) {
        var textProducto = $get('<%=this.txt_nombre_Producto.ClientID%>');
        textProducto.value = values;
    }
    function retornaPrecioProducto(values) {
        var textProducto = $get('<%=this.txt_precio_producto.ClientID%>');
        textProducto.value = values;
    }

    function retornaNombreCliente(values) {
        var textNombre = $get('<%=this.txt_nombre_cliente.ClientID%>');
        textNombre.value = values;
    }
    function retornaCodigoCliente(values) {
        var textNombre = $get('<%=this.txt_cod_cliente.ClientID%>');
        textNombre.value = values;
    }
    function alerta(valor) {
        window.alert(valor);
    }

    function ningunCaracter(evt) {
        var charCode = (evt.which) ? evt.which : event.keyCode
        return false;
    }
    function soloLetras(e) {
        tecla = (document.all) ? e.keyCode : e.which;
        if (tecla == 8) return true;
        patron = /[A-Za-z]/;
        te = String.fromCharCode(tecla);
        return patron.test(te);

    }
    function solonumeros(evt) {
        var charCode = (evt.which) ? evt.which : event.keyCode

        if (charCode > 31 && (charCode < 48 || charCode > 57))
            return false;
        return true;
    }
           
</script>

</html>
